package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.LeaseAgreementService;
import com.atguigu.lease.web.app.vo.agreement.AgreementDetailVo;
import com.atguigu.lease.web.app.vo.agreement.AgreementItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * @author LB
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2025年11月13日18:31:15
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;


    @Override
    public List<AgreementItemVo> customList() {
        List<AgreementItemVo> vo = leaseAgreementMapper.customList();
        Date time = new Date();
        for (AgreementItemVo s : vo) {
            //这一段判断的就是是否在租约中的用户
            boolean renewable =
                    LeaseStatus.SIGNED.equals(s.getLeaseStatus())
                    && s.getLeaseEndDate()!= null
                            //现在时间必须要小于租约最后的日期 小于才是租约中
                            //现在的时间要是大于租约时间那就是到期了
                    && time.before(s.getLeaseEndDate());
            s.setIsRenewable(renewable);
        }
        return vo;
    }

    @Override
    public AgreementDetailVo customGetDetailById( Long id) {
        return leaseAgreementMapper.customGetDetailById(id);
    }
}




